package xzy.Controller;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import xzy.dao.TeacherMapper;
import xzy.pojo.Student;
import xzy.pojo.Teacher;

import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "findTeacherPwd_Servlet")
public class findTeacherPwd_Servlet extends HttpServlet {
    ApplicationContext context=new ClassPathXmlApplicationContext("application.xml");
    TeacherMapper teacherMapper= (TeacherMapper) context.getBean("teacherMapper");
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("进入教师账号找回页面");
        request.setCharacterEncoding("utf-8");
        HttpSession session=request.getSession();
        String userName=request.getParameter("userName");
        try{
                Teacher teacher=new Teacher();
                teacher=teacherMapper.findTeacherByName(userName);
                if(teacher!=null){
                    session.setAttribute("findTeacherName",teacher.getTeacherName());
                    session.setAttribute("findTeacherPwd",teacher.getTeacherPwd());
                }else {
                    request.setAttribute("findTeacherPwd_error","系统并不存在此教师");;
                }
        }catch (Exception e){
            request.setAttribute("findTeacherPwd_error","系统并不存在此教师");;

        }finally {
            request.getRequestDispatcher("/toFindTeacherPwd.jsp").
                    forward(request,response);
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
